/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package univalle.eisc.pais.ai.searcheslab.model;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author victor
 */
public final class Stage {

    public static int[][] struct;
    private Robot robot;
    private Item item1;
    private Item item2;
    private Place place1;
    private Place place2;
    private List<Penalty> penalties;
    private Config config;

    public Stage(Config config) {
        this.config = config;
        try {
            struct = config.getStruct();
            procces();

        } catch (Exception ex) {
            Logger.getLogger(Stage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void procces() throws Exception {

        for (int i = 0; i < struct.length; i++) {
            for (int j = 0; j < struct[0].length; j++) {
                switch (struct[i][j]) {
                    case 0:
                        break;
                    case -1:
                        robot = new Robot(j, i);
                        break;
                    case -2:
                        item1 = new Item(j, i);
                        break;
                    case -3:
                        item2 = new Item(j, i);
                        break;
                    case -4:
                        place1 = new Place(j, i);
                        break;
                    case -5:
                        place2 = new Place(j, i);
                        break;
                    default:
                        if (penalties == null) {
                            penalties = new ArrayList<Penalty>();
                        }
                        penalties.add(new Penalty(j, i, struct[i][j]));

                }
            }
        }

    }

    public void reload() {
        try {
            penalties = null;
            procces();
        } catch (Exception ex) {
            Logger.getLogger(Stage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Config getConfig() {
        return config;
    }

    public List<Penalty> getPenalties() {
        return penalties;
    }

    public void setPenalties(List<Penalty> penalties) {
        this.penalties = penalties;
    }
    
    public void setConfig(Config config) {
        this.config = config;
    }

    public Robot getRobot() {
        return robot;
    }

    public void setRobot(Robot robot) {
        this.robot = robot;
    }

    public Item getItem1() {
        return item1;
    }

    public void setItem1(Item item1) {
        this.item1 = item1;
    }

    public Item getItem2() {
        return item2;
    }

    public void setItem2(Item item2) {
        this.item2 = item2;
    }

    public Place getPlace1() {
        return place1;
    }

    public void setPlace1(Place place1) {
        this.place1 = place1;
    }

    public Place getPlace2() {
        return place2;
    }

    public void setPlace2(Place place2) {
        this.place2 = place2;
    }
}
